package com.mjf.io.output;

import org.junit.Test;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;

public class BufferedWriterUse {

    @Test
    public void write() {
        String filePath = "D:\\coding\\idea\\java-stu\\output\\hello3.txt";

        BufferedWriter bw = null;

        try {
            bw = new BufferedWriter(new FileWriter(filePath));
            bw.write("hello1");
            bw.newLine();   // 出入一个基于当前系统的换行符
            bw.write("hello2");
            bw.newLine();
            bw.write("hello3");
            bw.newLine();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if(bw != null) {
                    bw.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }

}
